import * as types from './../constants/ActionTypes';

/*
 * 策略列表
 ================================================================*/
export function fetchProduct({ start = 1, limit = 10, bossStatus = -1, bossType = -1 } = {}) {
  return  (dispatch) => {

    let payload = { 
      product_status : 0, 
      message : '加载中' 
    };
    
    dispatch({
      payload ,
      type: [types.FETCH_PRODUCTS, types.FETCH_PRODUCTS_SUCCESS, types.FETCH_PRODUCTS_FAILURE],
      meta: {
        fetch: [`members/strategy?page_no=${start}&page_size=${limit}`, {
        		method: 'post',
            body: `status=${bossStatus}&bosstype=${bossType}&orderfield=tdprofit`
        	}
        ]
      }  
    });
  };
}

/*
 * 策略持仓
 ================================================================*/
export function fetchHolding({ start = 1, limit = 10, pid } = {}) {
  return  (dispatch) => {

    let payload = { 
      holding_status : 0, 
      message : '加载中',
      pid : pid
    };

    dispatch({
      payload, 
      type: [types.FETCH_HOLDINGS, types.FETCH_HOLDINGS_SUCCESS, types.FETCH_HOLDINGS_FAILURE],
      meta: {
        fetch: [`members/strategyccforapp?page_no=${start}&page_size=${limit}`, {
            method: 'post',
            body: `gsid=${pid}`
          }
        ]
      }  
    });
  };
}

/*
 * 策略操作历史
 ================================================================*/
export function fetchHistory({ start = 1, limit = 5, pid } = {}) {
  return  (dispatch) => {

    let payload = { 
      history_status : 0, 
      message : '加载中',
      pid : pid
    };

    dispatch({
      payload, 
      type: [types.FETCH_HISTORYS, types.FETCH_HISTORYS_SUCCESS, types.FETCH_HISTORYS_FAILURE],
      meta: {
        fetch: [`members/strategyhisforapp?page_no=${start}&page_size=${limit}`, {
            method: 'post',
            body: `gsid=${pid}`
          }
        ]
      }  
    });
  };
}

/*
 * 操作历史点赞
 ================================================================*/
export function praiseHistory({pid, mid, type = 1} = {}) {
  return  (dispatch) => {
    
    let payload = { 
      history_praise_status : 0, 
      message : '加载中',
      pid : pid,
      mid : mid
    };

    dispatch({
      payload,
      type: [types.PRAISE_HISTORY, types.PRAISE_HISTORY_SUCCESS, types.PRAISE_HISTORY_FAILURE],
      meta: {
        fetch: [`gaoshou/praise`, {
            method: 'post',
            body: `gsid=${pid}&mid=${mid}&type=${type}`
          }
        ]
      }  
    });
  };
}

/*
 * 策略关注
 ================================================================*/
export function SignProduct(pid) {
  return  (dispatch) => {
    let payload = { 
      product_sign_status : 0, 
      message : '加载中',
      pid : pid
    };
    dispatch({
      payload ,
      type: [types.SIGN_PRODUCT, types.SIGN_PRODUCT_SUCCESS, types.SIGN_PRODUCT_FAILURE],
      meta: {
        fetch: [`member/strategygz`, {
            method: 'post',
            body: `gsid=${pid}&operate=1`
          }
        ]
      }  
    });
  };
}

/*
 * 策略取消关注
 ================================================================*/
export function UnSignProduct(pid) {
  return  (dispatch) => {
    let payload = { 
      product_unsign_status : 0, 
      message : '加载中',
      pid : pid
    };
    dispatch({
      payload,
      type: [types.UNSIGN_PRODUCT, types.UNSIGN_PRODUCT_SUCCESS, types.UNSIGN_PRODUCT_FAILURE],
      meta: {
        fetch: [`member/strategygz`, {
            method: 'post',
            body: `gsid=${pid}&operate=2`
          }
        ]
      }  
    });
  };
}

/*
 * 策略点赞
 ================================================================*/
export function PraiseProduct(pid, type = 1) {
  return  (dispatch) => {
    let payload = { 
      product_praise_status : 0, 
      message : '加载中',
      pid : pid,
      type : type
    };
    dispatch({
      payload, 
      type: [types.PRAISE_PRODUCT, types.PRAISE_PRODUCT_SUCCESS, types.PRAISE_PRODUCT_FAILURE],
      meta: {
        fetch: [`gaoshou/praise`, {
            method: 'post',
            body: `gsid=${pid}&type=${type}`
          }
        ]
      }  
    });
  };
}


/*
 * 产品列表 - 复位
 ================================================================*/
export function resetProduct(){
  return (dispatch) => {
        let payload = {
            product_status: 0,
            product_praise_status : 0,
            product_unsign_status : 0,
            product_sign_status : 0,
            history_praise_status : 0,
            holding_status : 0,
            history_status : 0,
            message: '加载中',
            results : []
        };
        
        dispatch({
            payload,
            type : types.RESET_PRODUCTS
        });
    };
}